package com.hdjk.view.activity.main;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.hdjk.view.R;
import com.hdjk.view.fragment.main.WelFragment;
import com.hdjk.view.util.UserTokenUtil;
import com.lst.projectlib.base.BaseActivity;

/**
 * 首次打开banner页
 */
public class FirstInstallActivity extends BaseActivity {
	private static final String[] CONTENT = new String[]{"A","B","C"};
	private Button btnSkip,btnOpen;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void initView(Bundle savedInstanceState) {
		setContentView(R.layout.activity_first_install);
		FragmentPagerAdapter adapter = new GoogleMusicAdapter(
				getSupportFragmentManager());

		ViewPager pager = (ViewPager) findViewById(R.id.pager);
		/*btnSkip=(Button) findViewById(R.id.btnSkip);
		btnSkip.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				intentToPage();
			}
		});*/
		btnOpen=(Button) findViewById(R.id.btnOpen);
		btnOpen.setText("开启智投");
		btnOpen.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				intentToPage();
			}
		});
		pager.setAdapter(adapter);
		pager.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
//				if(arg0==CONTENT.length-1){
					//btnSkip.setVisibility(View.GONE);
//					btnOpen.setVisibility(View.VISIBLE);
//				}else{
					//btnSkip.setVisibility(View.VISIBLE);
//					btnOpen.setVisibility(View.GONE);
//				}
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});
	}

	@Override
	protected void initData() {
	}

	class GoogleMusicAdapter extends FragmentPagerAdapter {
		public GoogleMusicAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return CONTENT[position % CONTENT.length].toUpperCase();
		}

		@Override
		public int getCount() {
			return CONTENT.length;
		}

		@Override
		public Fragment getItem(int position) {
			switch (position) {
				case 0 :// 第一个Fragment
					WelFragment welFragment1=new WelFragment();
					Bundle bundle1=new Bundle();
					bundle1.putInt("drawableId", R.drawable.img_first_install_1);
					welFragment1.setArguments(bundle1);
					return welFragment1;
				case 1 :// 第二个Fragment
					WelFragment welFragment2=new WelFragment();
					Bundle bundle2=new Bundle();
					bundle2.putInt("drawableId", R.drawable.img_first_install_2);
					welFragment2.setArguments(bundle2);
					return welFragment2;
				case 2 :// 第三个Fragment
					WelFragment welFragment3=new WelFragment();
					Bundle bundle3=new Bundle();
					bundle3.putInt("drawableId", R.drawable.img_first_install_3);
					bundle3.putBoolean("isLast", true);
					welFragment3.setArguments(bundle3);
					return welFragment3;
				default :
					WelFragment welFragmentOther=new WelFragment();
					Bundle bundleOther=new Bundle();
//					bundleOther.putInt("drawableId", R.drawable.img_first_install_4);
					bundleOther.putBoolean("isLast", true);
					welFragmentOther.setArguments(bundleOther);
					return welFragmentOther;
			}

		}

	}
	
	@Override
	public void onBackPressed() {
		intentToPage();
	}
	
	public void intentToPage(){
//		if(UserTokenUtil.isLogin(this)){
			Intent intent = new Intent(FirstInstallActivity.this, MainTabActivity.class);
			startActivity(intent);
//		}else{
//			Intent intent = new Intent(FirstInstallActivity.this, LoginActivity.class);
//			startActivity(intent);
//		}
		FirstInstallActivity.this.finish();
	}
}
